package net.lzzy.mapper;

import net.lzzy.entity.Comment;
import org.apache.ibatis.annotations.*;

@Mapper
public interface CommentMapper {

//    //属性名与表列名不对应
//    //方法1：使用别名
//    //根据ID查询评论
//    @Select("SELECT *, id as idx FROM t_comment WHERE id=#{id}")
//
//    //方法2：使用ReslutMap注解
//    @Results(id = "commentMap", value ={
//           @Result(column = "id", property = "idx", id=true)
//    })
//
//    //多参数传递时使用Param注解
//    @Select("SELECT * FROM t_comment WHERE a_id=#{aId} AND author=#{author}")
//    public Comment find(@Param("aId") Integer aId, @Param("author") String author);

    //根据ID查询评论
    @Select("SELECT * FROM t_comment WHERE id=#{id}")
    public Comment findById(Integer id);

    //插入新的评论
    @Insert("INSERT INTO t_comment(a_id, author, content) VALUES (#{aId}, #{author}, #{content})")
    public int insertComment(Comment comment);

    //更新评论
    @Update("UPDATE t_comment SET content=#{content} WHERE id=#{id}")
    public int updateComment(Comment comment);

    //删除评论
    @Delete("DELETE FROM t_comment WHERE id=#{id}")
    public int deleteComment(Integer id);
}
